﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;

namespace SilverlightMultiLevelNavigationExample
{
    public class Navigation : List<MenuItem>
    {
        public Navigation()
            : base()
        {
            XDocument document = XDocument.Load("Assets/Navigation.xml");

            foreach (var MainMenu in document.Descendants("MainMenu"))
            {
                Add(new MenuItem
                {
                    Name = MainMenu.Attribute("name").Value,
                    Url = MainMenu.Attribute("url").Value,
                    SubMenuItems = new List<MenuItem>(
                        from SubMenu in MainMenu.Descendants("SubMenu")
                        select new MenuItem
                        {
                            Name = SubMenu.Attribute("name").Value,
                            Url = SubMenu.Attribute("url").Value
                        })
                });
            }
        }

    }

    public class MenuItem
    {
        public string Name { get; set; }
        public string Url { get; set; }
        public List<MenuItem> SubMenuItems { get; set; }
    }
}
